﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NhibernateSample.Domain;
using NHibernate.Cfg;

namespace NhibernateSample.Data
{
	public class CustomerHelper
	{
		protected ISession _session { get; set; }

		public CustomerHelper()
		{
			NhibernateHelper nHibernateHelper = new NhibernateHelper();
			_session = nHibernateHelper.GetSession();
		}

		public CustomerHelper(ISession session)
		{
			_session = session;
		}

		public int CreateCustomer(Customer customer)
		{
			object objId = _session.Save(customer);
			_session.Flush();

			return (int)objId;
		}

		public Customer GetCustomerById(int id)
		{
			return _session.Get<Customer>(id);
		}
	}
}
